package io.renren.project.jinxitai.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.renren.common.utils.R;
import io.renren.modules.wyzs.mobile_BillAdapterMoudle.BillTemp;
import io.renren.modules.wyzsphone.utils.Utils;
import io.renren.project.hongchang.entity.AddCar;
import io.renren.project.hongchang.service.HongchangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping("/jinxitai")
public class JinxitaiController {

    @Autowired
    HongchangService hongchangService;

    @RequestMapping("/getNumber")
    public R getSalesOrder(@RequestBody String jsonStr)
    {
        List<String> list=new ArrayList<>();
        for(int i=0;i<11;i++)
        {
            String uuid= UUID.randomUUID().toString();
            String s=  uuid.replace("-","");
            list.add(s);
        }

        return R.ok().put("data", list);
    }


    @RequestMapping("/getAllTask")
    public R getAllTask(@RequestBody String jsonStr) {
        Map<String, Object> params = Utils.JsonToMap(jsonStr);
        Map o = hongchangService.getAllTask(params);

        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }

    @RequestMapping("/getBillTemp")
    public R getBillTemp(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        BillTemp o= hongchangService.getBillTemp(params);
        return R.ok().put("data",o);
    }

    @RequestMapping("/getSalesBill")
    public R getSalesBill(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getSalesBill(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }


    @RequestMapping("/getAllOrder")
    public R getAllOrder(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getAllOrder(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }

    @RequestMapping("/getSalesItem")
    public R getSalesItem(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getSalesItem(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }
    @RequestMapping("/getSalesAccountListByItemId")
    public R getSalesAccountListByItemId(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getSalesAccountListByItemId(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }


    @RequestMapping("/getSalesAccountListByItemIdX05")
    public R getSalesAccountListByItemIdX05(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getSalesAccountListByItemIdX05(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }

    @RequestMapping("/getSalesItemByAccountID")//W_GetSalesItemByAccountID
    public R getSalesItemByAccountID(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getSalesItemByAccountID(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }


    //新增任务单
    @RequestMapping("/saveBillX05")
    public R saveBillX05(@RequestBody String jsonStr )
    {
        Gson _gson=new Gson();

        Map<String, Object> params = _gson.fromJson(jsonStr, new TypeToken<Map<String, Object>>() {
        }.getType());
        Map o= hongchangService.saveBillX05(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        }else if("1".equals(o.get("state"))){
            return R.error(1,"操作失败");}
        else {

            return R.ok().put("data", o);
        }
    }


    //新增任务单
    @RequestMapping("/addTask")
    public R addTask(@RequestBody String jsonStr )
    {
        Gson _gson=new Gson();

        Map<String, Object> params = _gson.fromJson(jsonStr, new TypeToken<Map<String, Object>>() {
        }.getType());

        //Utils.setDoubleToInt(params,"organizeId");
        // Utils.setDoubleToInt(params,"balance");
        Map o= hongchangService.addTask(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        }else if("1".equals(o.get("state"))){
            return R.error(1,"操作失败");}
        else {
            return R.ok().put("data", o);
        }
    }

    //作废任务单
    @RequestMapping("/cancleTask")
    public R cancleTask(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.cancleTask(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        }else if("1".equals(o.get("state"))){
            return R.error(1,"操作失败");}
        else {
            return R.ok().put("data", o);
        }
    }

    //获取批量下单列表
    @RequestMapping("/getAppOrderList")
    public R getAppOrderList(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getAppOrderList(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {
            return R.ok().put("data", o);
        }
    }

    //获取批量下单详情
    @RequestMapping("/getAppOrderBill")
    public R getAppOrderBill(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Map o= hongchangService.getAppOrderBill(params);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        } else {

            return R.ok().put("data", o);
        }
    }


    //给批量下单增加车辆
    @RequestMapping("/AppCarListAdd")
    public R AppCarListAdd(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Gson _gson=new Gson();
        AddCar addCar=_gson.fromJson(jsonStr, AddCar.class);
        Map o= hongchangService.AppCarListAdd(params,jsonStr);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        }else if("1".equals(o.get("state"))){
            return R.error(1,"操作失败");}
        else {
            return R.ok().put("data", o);
        }
    }

    //删除批量下单的车辆
    @RequestMapping("/AppCarListDel")
    public R AppCarListDel(@RequestBody String jsonStr)
    {
        Map<String,Object> params = Utils.JsonToMap(jsonStr);
        Gson _gson=new Gson();
        Map o= hongchangService.AppCarListDel(params,jsonStr);
        if ("2".equals(o.get("state"))) {
            return R.uidError("uid过期");
        }else if("1".equals(o.get("state"))){
            return R.error(1,"操作失败");}
        else {
            return R.ok().put("data", o);
        }
    }

}